<?php
namespace app\index\model;
use think\Model;

class Result extends model{
	function findatatime($datatime){
		$res = db('result')->where('datatime',$datatime)->count();
		return $res;
	}
	function findall(){
		$res = db('result')->select();
		return $res;
	}
	function share($user_id,$jiangjin){
    	model('user')->where(['id'=>$user_id])->setInc('employ' , $jiangjin);
		//按占成扣成
        $occupy = db("occupy")->where(['user_id'=>$user_id])->find();
        //where('id=5')->setDec('score',5); 

        $jiangjin = $jiangjin / 100.0;

        $user = model('user')->find($user_id);
        model('user')->where(['id'=>$user['topuser']])->setDec('employ',$jiangjin*$occupy['daili']);

        $user = model('user')->find($user['topuser']);
        model('user')->where(['id'=>$user['topuser']])->setDec('employ',$jiangjin*$occupy['zongdai']);

    	$user = model('user')->find($user['topuser']);
        model('user')->where(['id'=>$user['topuser']])->setDec('employ',$jiangjin*$occupy['gudong']);

        $user = model('user')->find($user['topuser']);
        model('user')->where(['id'=>$user['topuser']])->setDec('employ',$jiangjin*$occupy['dagudong']);

        $user = model('user')->find($user['topuser']);
        model('user')->where(['id'=>$user['topuser']])->setDec('employ',$jiangjin*$occupy['zongjian']);

    	$user = model('user')->find($user['topuser']);
        model('user')->where(['id'=>$user['topuser']])->setDec('employ',$jiangjin*$occupy['houtai']);
	}

}